package com.yang.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.android.tu.loadingdialog.LoadingDailog;
import com.jaeger.library.StatusBarUtil;
import com.yang.demo.ActivityCollector;
import com.yang.demo.MainActivity;
import com.yang.demo.R;
import com.yang.demo.greendao.DaoManager;
import com.yang.demo.util.Loader;
import com.yang.demo.util.ScreenUtils;
import com.yang.demo.util.XlsToJson;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by yangwenwen on 2018/3/16.
 */
public class LoginActivity extends AppCompatActivity {

    @BindView(R.id.tv_login)
    TextView tvLogin;
    @BindView(R.id.tv_register)
    TextView tvRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        ScreenUtils.setWindowStatusBarColor(this, R.color.white);
        StatusBarUtil.setDarkMode(this);

        if (DaoManager.getInstance().getDataModel() == null ||
                DaoManager.getInstance().queryDataList().size() == 0) {
            Loader.show(this, "数据库初始化中...");
            new Thread(new Runnable() {
                @Override
                public void run() {
                    XlsToJson.start();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Loader.stop();
                        }
                    });
                }
            }).start();
        }
    }

    @OnClick({R.id.tv_login, R.id.tv_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_login:
                Intent intent = new Intent();
                intent.setClass(this, Login2Activity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.tv_register:
                Intent intent1 = new Intent(this, RegisterActivity.class);
                startActivity(intent1);
                break;
            default:
                break;
        }
    }
}
